
package qdu.java.recruit.service.impl;

import org.springframework.stereotype.Service;
import qdu.java.recruit.entity.UserEntity;
import qdu.java.recruit.mapper.UserMapper;
import qdu.java.recruit.service.UserService;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public UserEntity getUser(int userId) {
        return userMapper.getUser(userId);
    }

    @Override
    public boolean updateUser(UserEntity userEntity) {

        String password = userEntity.getPassword();

        int result;
        userEntity.setPassword(password);
        result = userMapper.updateUser(userEntity);
        return result > 0;
    }

    @Override
    public boolean registerUser(UserEntity userEntity) {

        String mobile = userEntity.getMobile();
        if (userMapper.getUserByMobile(mobile) != null) {
            return false;
        }

        String password = userEntity.getPassword();

        int result;
        userEntity.setPassword(password);
        result = userMapper.saveUser(userEntity);
        return result > 0;

    }

    @Override
    public boolean loginUser(String mobile, String password) {

        if (userMapper.getUserByMobile(mobile) == null) {
            return false;
        }
        String passwordDB = userMapper.getUserByMobile(mobile).getPassword();
        return password.equals(passwordDB);
    }

    @Override
    public UserEntity getUserByMobile(String mobile) {

        return userMapper.getUserByMobile(mobile);
    }





}

